<?php
class ConnectionMySQL {

	
	private $connnection;	
	/*
	public function getConnection() {
		return $this->connnection;
	}
	
	public function setConnection($conn) {
		$this->connnection = $conn;
	}
	*/

	public function __construct() {		
		$this->connnection = null;
	}	
	
	public function connect() {	
		//$this->connnection = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DBNAME);
		//$this->connnection->query('set names utf8;');
		$this->connnection = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD);
		mysql_select_db(DB_DBNAME, $this->connnection);
		mysql_query("set names 'utf8'");
		
	}
	
	public function disconnect() {
		//Using mysql_close() isn't usually necessary, 
		//as non-persistent open links are automatically closed 
		//at the end of the script's execution.
				
		//$this->connnection->close();
		//mysql_close($this->connnection);
	}
	
	public function query($sqlQuery) {
		//$result = $this->connnection->query($sqlQuery);
		$result = mysql_query($sqlQuery);
		return $result;
	}	
	
	public function get_value_returned($query_result) {
		$value = -1;
		/*
		if(mysqli_num_rows($query_result) > 0) {			
			$rows = mysqli_fetch_array ($query_result);
			$value = $rows[0];			
		}
		*/	

		if(mysql_num_rows($query_result) > 0) {			
			$rows = mysql_fetch_array ($query_result);
			$value = $rows[0];			
		}
		
		return $value;
	}
	
	public function get_object_returned($query_result) {
		$object = null;
		/*
		if(mysqli_num_rows($query_result) > 0) {
			$object = mysqli_fetch_array ($query_result);
		}
		*/
		if(mysql_num_rows($query_result) > 0) {
			$object = mysql_fetch_array ($query_result);
		}
		
		return $object;
	}
	
	public function last_insert_id() {
		//$result = $this->connnection->query ( "SELECT last_insert_id();" );
		//$row = mysqli_fetch_array ( $result );
		$result = mysql_query ( "SELECT last_insert_id();" );
		$row = mysql_fetch_array ( $result );
		$last_insert_id = $row ['last_insert_id()'];
		
		return $last_insert_id;
	}
	
	public function escape_string($string) {
		return mysql_real_escape_string($string);		
	}
}

?>